<template>
  <div class="goods-hot">
    <h3>{{ test(type) }}</h3>
    <!-- 商品区块 -->
    <RouterLink
      to="/"
      class="goods-item"
      v-for="good in goodList"
      :key="good.id"
    >
      <img :src="good.picture" alt="" />
      <p class="name ellipsis">{{ good.desc }}</p>
      <p class="desc ellipsis">{{ good.name }}</p>
      <p class="price">&yen;{{ good.price }}</p>
    </RouterLink>
  </div>
</template>
<script>
// import { computed } from 'vue'
// import GoodItem from '@/views/Category/components/good-item'
import { findHotGoods } from '@/api/good'
import { ref } from 'vue-demi'
import { useRoute } from 'vue-router'
export default {
  name: 'GoodsHot',
  props: {
    type: {
      type: Number
    }
  },

  setup (props) {
    const TYPE = {
      1: '24小时热销',
      2: '周热销',
      3: '总热销'
    }
    // 计算属性判断枚举
    // const res = computed(() => {
    //   return TYPE[props.type]
    // })
    // 函数方法判断枚举
    function test (type) {
      return TYPE[type]
    }

    const route = useRoute()
    const goodList = ref([])
    async function getGoodList () {
      const res = await findHotGoods({ id: route.params.id, type: props.type })
      // console.log(res.data.result)
      goodList.value = res.data.result
    }

    getGoodList()

    return {
      goodList,

      test
    }
  }
}
</script>
<style scoped lang="less">
.goods-hot {
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
}
</style>

<style scoped lang="less">
.goods-hot {
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
  .goods-item {
    display: block;
    padding: 20px 30px;
    text-align: center;
    background: #fff;
    img {
      width: 160px;
      height: 160px;
    }
    p {
      padding-top: 10px;
    }
    .name {
      font-size: 16px;
    }
    .desc {
      color: #999;
      height: 29px;
    }
    .price {
      color: @priceColor;
      font-size: 20px;
    }
  }
}
</style>
